package com.laomou.poker.rule.landlord;

import java.util.ArrayList;
import java.util.List;

import com.laomou.poker.Poker;
import com.laomou.poker.PokerGroup;
import com.laomou.poker.PokerNum;
import com.laomou.poker.player.AiPlayer;
import com.laomou.poker.player.PlayerType;

public final class LaoMouPlayer extends AiPlayer {
    private List<PokerGroup> straight = new ArrayList<PokerGroup>();
    private List<PokerGroup> bigbong = new ArrayList<PokerGroup>();

    public LaoMouPlayer() {
        setPlayerName("LaoMou");
    }

    @Override
    public PokerGroup getFirstDiscardPoker() {
        PokerGroup pgs = new PokerGroup();
        int i = (int) (Math.random() * getPlayerPoker().size());
        pgs.addPoker(getPlayerPoker().get(i));
        return pgs;
    }

    @Override
    public PokerGroup getDiscardPoker(PlayerType type, PokerGroup pg) {
        List<PokerGroup> bigPoker = new ArrayList<PokerGroup>();
        getGreaterPokerGroup(pg, bigPoker);
        int i = (int) (Math.random() * bigPoker.size());
        return bigPoker.get(i);
    }

    @Override
    public boolean isRobFirst() {
        int ret = 0;
        for (Poker poker : getPlayerPoker()) {
            if (poker.value() == 2) {
                ret += 2;
            }
            if (poker.value() == PokerNum.小王.value()) {
                ret += 3;
            }
            if (poker.value() == PokerNum.大王.value()) {
                ret += 4;
            }
        }
        return ret > 3;
    }

    @Override
    public void analysePoker() {
        List<Poker> tmp = new ArrayList<Poker>();
        tmp.addAll(getPlayerPoker());
        getPokerByPokerGroupType(bigbong, tmp, LandlordType.炸弹, 4);
        getPokerByPokerGroupType(bigbong, tmp, LandlordType.双王, 2);
        tmp.removeAll(bigbong);
        getPokerByPokerGroupType(straight, tmp, LandlordType.三带一, 4);
        //getPokerByPokerGroupType(straight, tmp, LandlordType.双顺子, 6, 16);
        //getPokerByPokerGroupType(straight, tmp, LandlordType.三顺子, 6, 18);
        tmp.removeAll(straight);
    }
}
